package com.yc.sakuralxm.uestcscanning.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;



public abstract class BaseFragment extends Fragment {
    @Override
    public void onResume() {
        super.onResume();
    }
    @Override
    public void onPause() {
        super.onPause();
    }
    protected View rootView;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        int lId = onCreateGetLayoutId();
        if (rootView == null) {
            if (lId == 0) {//为0时必须重写onCreateView()方法
                rootView = onCreateView();
            } else {
                rootView = inflater.inflate(lId, null);
            }
            onCreateInitViews();
        } else {
            ViewGroup parent = ((ViewGroup) rootView.getParent());
            if (parent != null)
                parent.removeView(rootView);
        }
        return rootView;
    }
    protected View onCreateView(){
        return null;
    }

    protected abstract int onCreateGetLayoutId();

    protected abstract void onCreateInitViews();

    public View findViewById(int id) {
        if (rootView != null) {
            return rootView.findViewById(id);
        }
        return null;
    }



    public void finish() {
        getActivity().finish();
    }
//    @Subscribe
//    public void onEventMainThread(EventList event) {
//    }

}
